package com.car.config;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.util.Properties;

public class DataSourceConfig {
    /**
     *
     * @return
     * @throws Exception
     */
    public static DataSource getDruidDataSource() throws Exception {
        Properties properties = new Properties();
        properties.load(new FileInputStream("druid.properties"));
        return  DruidDataSourceFactory.createDataSource(properties);
    }

    /**
     * 获取数据库连接对象
     *
     */
    public static Connection getConnection() throws Exception {
        return getDruidDataSource().getConnection();
    }
}
